package com.hyphenate.helpdesk.easeui.util;

import android.content.Context;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.hyphenate.chat.Message;
import com.hyphenate.helpdesk.R;
import com.hyphenate.helpdesk.model.AgentInfo;
import com.hyphenate.helpdesk.model.MessageHelper;
import com.simga.library.utils.LogUtil;
import com.simga.library.utils.glide.GlideUtil;

/**
 */
public class UserUtil {

    public static void setAgentNickAndAvatar(Context context, Message message, ImageView userAvatarView, TextView usernickView){
        AgentInfo agentInfo = MessageHelper.getAgentInfo(message);
        if (usernickView != null){
            usernickView.setText(message.getUserName()==null?"飞腾赚客":message.getUserName());
            if (agentInfo != null){
                if (!TextUtils.isEmpty(agentInfo.getNickname())) {
                    usernickView.setText(agentInfo.getNickname()==null?"飞腾赚客":agentInfo.getNickname());
                }
            }
        }
        if (userAvatarView != null){
            GlideUtil.loadCirclePicture("https://img.zcool.cn/community/01182c59eda88da801216a4bc402b0.jpg@1280w_1l_2o_100sh.jpg", userAvatarView, R.drawable.default_image);
            if (agentInfo != null){
                if (!TextUtils.isEmpty(agentInfo.getAvatar())) {
                    String strUrl = agentInfo.getAvatar();
                    // 设置客服头像
                    if (!TextUtils.isEmpty(strUrl)) {
                        if (!strUrl.startsWith("http")) {
                            strUrl = "http:" + strUrl;
                        }
                        GlideUtil.loadPicture(strUrl,userAvatarView,R.drawable.hd_default_expression);
                    }else{
                        GlideUtil.loadCirclePicture("https://img.zcool.cn/community/01182c59eda88da801216a4bc402b0.jpg@1280w_1l_2o_100sh.jpg", userAvatarView, R.drawable.default_image);
                    }
                }
            }
        }
    }

    public static void setCurrentUserNickAndAvatar(Context context,ImageView userAvatarView, TextView userNickView){
        if (userAvatarView != null){
            userAvatarView.setImageResource(R.drawable.hd_default_avatar);
        }
    }
}
